﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NS_DBOP;

public partial class Flow_NewStep : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DataSet ds = new DBoperate().ExecuteQuery("select * from FlowAction", 0, 0, "action");
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                this.drpAction.Items.Add(new ListItem(dr["Name"].ToString(), dr["ID"].ToString()));
            }
            if (Request.QueryString["flowid"] != null)
            {
                
                string num = new DBoperate().ExecuteScalar("select Num from FlowStep where ID=" + Request.QueryString["stepid"]).ToString();
                this.txtNum.Text = num ;
            }
            if (Request.QueryString["flid"] != null)
            {
                DataSet dsfs = new DBoperate().ExecuteQuery("select * from FlowStep where FlowID=" + Request.QueryString["flid"].ToString(), 0, 0, "flow");
                this.txtNum.Text =Convert.ToString(dsfs.Tables[0].Rows.Count+1);
            }
        }

    }
    protected void btnSevr_Click(object sender, EventArgs e)
    {
        string action = this.drpAction.SelectedItem.Value.ToString(); ;
        int  num =Convert.ToInt32(this.txtNum.Text);
        string join = this.drpJoin.SelectedItem.Value.ToString();
        string end = this.drpEnd.SelectedItem.Value.ToString();
        string des = this.txtDes.Text;
        int flowid = Convert.ToInt32(Request.QueryString["flowid"]);
        if (Request.QueryString["stepid"] != null)
        {
            string strSql="update FlowStep set ActionID="+action+",IsJoin="+join+",Des='"+des+"',Num="+num
                +",IsEnd="+end+" where FlowID="+flowid;
            int result = new DBoperate().ExecuteUpdate(strSql);
            if (result > 0)
            {
                Response.Write("<script language=javascript>alert('保存成功！');window.location.href='FlowStep.aspx?id="+Request.QueryString["flowid"]+"'</script>");
            }
            else
            {
                Response.Write("<script language=javascript>alert('保存失败！')</script>");
            }
        }
        else
        {
            string strSql = "insert into FlowStep values(" + action + "," + join + ",'" + des + "'," +
                num + ","+flowid+"," + end + ")";
            int result = new DBoperate().ExecuteUpdate(strSql);
            if (result > 0)
            {

                Response.Write("<script language=javascript>alert('保存成功！');window.location.href='FlowStep.aspx'</script>");
            }
            else
            {
                Response.Write("<script language=javascript>alert('保存失败！')</script>");
            }
        }
    }
    protected void btnReturn_Click(object sender, EventArgs e)
    {
        string id=null;
        if(Request.QueryString["flid"]!=null)
        {
            id=Request.QueryString["flid"].ToString();
        }
        if(Request.QueryString["flowid"]!=null)
        {
            id=Request.QueryString["flowid"].ToString();
        }
        Response.Write("<script language=javascript>window.location.href='FlowStep.aspx?id="+id+"'</script>");
    }
}
